package com.tgpms.web.element.controller;

import cn.hutool.core.util.IdUtil;
import com.tgpms.common.PageUtils;
import com.tgpms.common.R;
import com.tgpms.web.element.entity.WsAccept;
import com.tgpms.web.element.service.WsAcceptService;
import com.tgpms.web.element.vo.WsDocVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;




/**
 * 验收表
 *
 * @author jl
 * @since 2020-07-13 11:33:18
 */
@Api(value = "WsAcceptController", tags = "验收表相关接口")
@RestController
@RequestMapping("/ev/wsaccept")
public class WsAcceptController {
    @Autowired
    private WsAcceptService wsAcceptService;

    /**
     * 根据验收表id分页查询所有附件信息
     */
    @PostMapping("/getAnnexById")
    @ApiOperation(value = "根据验收表id分页查询所有附件信息", notes = "根据验收表id分页查询所有附件信息", httpMethod = "POST")
    public R getAnnexById(@RequestParam Map<String,Object> params){
        if (params.get("id") == null) {
            return R.error("验收记录id不能为空!");
        }
        String id =(String) params.get("id");
        WsAccept wsAccept = wsAcceptService.getById(id);
        if (wsAccept == null) {
            return R.error("该验收记录不存在!");
        }
        PageUtils page = wsAcceptService.getAnnexById(id,params);

        return R.ok(page);
    }

    /**
     * 带条件分页查询wsAccept
     */
    @GetMapping("/list")
    @ApiOperation(value = "带条件分页查询wsAccept", notes = "带条件分页查询wsAccept", httpMethod = "GET")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wsAcceptService.queryPage(params);

	    return R.ok(page);
    }


    /**
     * 根据主键查询wsAccept
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据主键查询wsAccept", notes = "根据主键查询wsAccept", httpMethod = "GET")
    public R info(@PathVariable("id") String id){
		WsAccept wsAccept = wsAcceptService.getById(id);

        return R.ok(wsAccept);
    }

    /**
     * 新增wsAccept
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增wsAccept", notes = "新增wsAccept", httpMethod = "POST")
    public R save(@RequestBody WsAccept wsAccept){
        wsAccept.setId(IdUtil.fastSimpleUUID());
		wsAcceptService.save(wsAccept);

        return R.ok();
    }

    /**
     * 修改wsAccept
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改wsAccept", notes = "修改wsAccept", httpMethod = "PUT")
    public R update(@RequestBody WsAccept wsAccept){
		wsAcceptService.updateById(wsAccept);

        return R.ok();
    }

    /**
     * 删除wsAccept
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "根据主键ids删除wsAccept", notes = "根据主键ids删除wsAccept", httpMethod = "DELETE")
    public R delete(@RequestBody String[] ids){
		wsAcceptService.removeWsAcceptByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询验收附件图片,返回base64
     */
    @PostMapping("/getImgBase64ById")
    @ApiOperation(value = "查询验收附件图片,返回base64", notes = "查询验收附件图片,返回base64", httpMethod = "POST")
    public R getImgBase64ById(@RequestParam("id") String id) {
        List<WsDocVo> wsDocVos = wsAcceptService.getImgById(id);
        return R.ok(wsDocVos);
    }

}
